var EnumSprite = cc.Class({
    extends: cc.Sprite,

    properties: {
        spriteFrames:{
            default:[],
            type:[cc.SpriteFrame],
        }, 

        _index: 0,
        index: {
            type: cc.Integer,
            range: [0, 100],
            set(value) {
                value = parseInt(value);
                if (value < 0 || value >= this.spriteFrames.length) {
                    return;
                }
                
                this._index = value;
                this.spriteFrame = this.spriteFrames[value];
                if (this.spriteFrame) {
                    this.spriteName = this.spriteFrame.name;
                }
                if (CC_EDITOR) {
                    this._refresh();
                }
            },

            get() {
                return this._index;
            }
        },
    },

    //实现在编辑器刷新功能
    _refresh() {
        Editor.Utils.refreshSelectedInspector('node', this.uuid);
    },

    __preload: function() {
        this._super();
        if (CC_EDITOR) {
            this._refresh();
        }
    },

});

cc.Class.Attr.setClassAttr(EnumSprite, 'spriteFrame', 'visible', false);
cc.Class.Attr.setClassAttr(EnumSprite, '_atlas', 'visible', false);
cc.Class.Attr.setClassAttr(EnumSprite, 'fillCenter', 'visible', function() {
    return this._type === cc.Sprite.Type.FILLED;
});
cc.Class.Attr.setClassAttr(EnumSprite, 'fillStart', 'visible', function() {
    return this._type === cc.Sprite.Type.FILLED;
});
cc.Class.Attr.setClassAttr(EnumSprite, 'fillEnd', 'visible', function() {
    return this._type === cc.Sprite.Type.FILLED;
});
cc.Class.Attr.setClassAttr(EnumSprite, 'fillRange', 'visible', function() {
    return this._type === cc.Sprite.Type.FILLED;
});
cc.Class.Attr.setClassAttr(EnumSprite, 'srcBlendFactor', 'visible', function() {
    return this._type === cc.Sprite.Type.FILLED;
});
cc.Class.Attr.setClassAttr(EnumSprite, 'dstBlendFactor', 'visible', function() {
    return this._type === cc.Sprite.Type.FILLED;
});

cc.EnumSprite = module.exports = EnumSprite;